package com.mcxx.convert;

import com.mcxx.modules.miniSalvation.check.entity.CheckEntity;
import com.mcxx.modules.miniSalvation.order.dto.CheckDTO;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import org.springframework.beans.BeanUtils;

import java.util.Date;


public class CheckConvert {


    public static CheckEntity convertCheckEntity(CheckDTO checkDTO, String batchNo, String checkState, String checkType){
        CheckEntity checkEntity = new CheckEntity();
        BeanUtils.copyProperties(checkDTO, checkEntity);

        checkEntity.setCreateTime(new Date());
        checkEntity.setCheckBatchNo(batchNo);
        checkEntity.setCheckState(checkState);
        checkEntity.setCheckType(checkType);

        return checkEntity;
    }

    public static CheckDTO convertCheckDTO(CheckEntity checkEntity){
        CheckDTO checkDTO = new CheckDTO();
        BeanUtils.copyProperties(checkEntity,checkDTO);

        checkDTO.setFamilySupport("0");

        if(CommonUtil.invalidArgs(checkDTO.getBusinessType())){
            if(Constant.BusinessStandType.CITY_DIBAO.equals(checkDTO.getStandType())||Constant.BusinessStandType.COUNTY_DIBAO.equals(checkDTO.getStandType())){
                checkDTO.setBusinessType(Constant.BusinessCode.DIBAO);
            }else if(Constant.BusinessStandType.CITY_TEKUN.equals(checkDTO.getStandType())||Constant.BusinessStandType.COUNTY_TEKUN.equals(checkDTO.getStandType())){
                checkDTO.setBusinessType(Constant.BusinessCode.TEKUN);
            }else {
                checkDTO.setBusinessType(Constant.BusinessCode.LINSHI);
            }
        }
        return checkDTO;
    }
}
